﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class frmInThongtinGV : Form
    {
        string makhoa;
        SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=SM;Integrated Security=True");
        public frmInThongtinGV()
        {
            InitializeComponent();
            get_Khoa();
        }


        DataSet FillDataset(string sql)
        {
            DataSet ds = new DataSet();
            try
            {
                SqlDataAdapter adap = new SqlDataAdapter(sql, connection);
                adap.Fill(ds);
                adap.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message);
            }
            return ds;
        }

        public void get_Khoa()
        {
            DataSet ds1 = FillDataset("Select Makhoa, Tenkhoa from T16_Khoa");
            colMakhoa.FieldName = "Makhoa";
            colTenkhoa.FieldName = "Tenkhoa";
            gridControl1.DataSource = ds1.Tables[0];
        }

        public void Get_DanhsachGV()
        {
            DataSet ds1 = FillDataset("SELECT MagvID , Hoten, NgaySinh, MatrinhdoID, Diachi FROM SM.dbo.T02_Giao_vien gv, T16_Khoa k  where k.Makhoa = gv.MaKhoa and k.Makhoa = N'" + makhoa + "'");
            colMaGV.FieldName = "MagvID";
            colHoten.FieldName = "Hoten";
            colNgaysinh.FieldName = "NgaySinh";
            colTrinhdo.FieldName = "MatrinhdoID";
            colDiachi.FieldName = "Diachi";
            gridControl2.DataSource = ds1.Tables[0];
        }


        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            makhoa = gridView1.GetRowCellValue(e.RowHandle, colMakhoa).ToString();
            Get_DanhsachGV();
        }

        private void btnIn_Click(object sender, EventArgs e)
        {
            rptThongtinGV rpt = new rptThongtinGV();
            rpt.DataSource = FillDataset("SELECT MagvID , gv.Makhoa, Hoten, NgaySinh, MatrinhdoID, Diachi FROM SM.dbo.T02_Giao_vien gv, T16_Khoa k  where k.Makhoa = gv.MaKhoa and k.Makhoa = N'" + makhoa + "'");
            rpt.BindData();
            rpt.PrintingSystem.PreviewFormEx.MdiParent = RibbonForm1.ActiveForm;
            rpt.ShowPreview();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
